package com.liyunc.demo.web.resources;

import com.liyunc.demo.model.entity.GoodsEntity;
import com.liyunc.demo.service.GoodsService;
import com.liyunc.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/api/v1/seckill")
public class GoodsResource {

    @Autowired
    private GoodsService seckillGoodsService;


    @RequestMapping("/findAll")
    public List<GoodsEntity> findAll() {
        return seckillGoodsService.findAll();

    }

    @RequestMapping("/findOne/{id}")
    public GoodsEntity findOne(@PathVariable("id") long id) {
        return seckillGoodsService.findOne(id);

    }


    @RequestMapping("/saveOrder/{id}")
    public Result saveOrder(@PathVariable("id") long id) {
        //假设从Session中取到了用户信息
        String userId = "jiuwenlong";
        return seckillGoodsService.saveOrder(id, userId);
    }
}
